var opt, salary_id;
var EmployeeData;
$(function() {
    //ldz 设置表单高度
    $("#form_core").height($(".form_tab").height()-$("#form_option").outerHeight());
    var param = new Object();
    param.p=false;
    var url = "/employee/query";
    var data = JSON.stringify(param);
    if (url){
        ajaxSubmit(url, data, function(data) {
            if (data!=null) {
            	EmployeeData=data;
            }
        });
    }
});


// 保存处理方法 ，新增及修改 。
function toSave() {
	//单据校验
	//if (!validate())
	//	return;
	var url;
	// 设置 主表数据
	var param = new Object();

	//param.userName = $("#userName").val();
	param.userid = $("#userid").val();
	param.company_id = $("#company_id").val();
	param.dept_id = $("#dept_id").val();
	param.sal_date = $("#sal_date").val();
	param.base_wage = $("#baseSalary").val();
	param.allowance = $("#extraSalary").val();
	param.absence_deduct = $("#absenceSalary").val();
	param.insurance = $("#insurancSalary").val();
	param.attendance_day = $("#attendanceDay").val();
	param.atten_abnormal_day = $("#attenAbnormalDay").val();
	param.actual_salary = $("#realSalary").val();
	
	if (opt === 'm') {
		// 进行修改数据库处理
		//处理主表数据
		param.__status = 'update';
		url = "/salary/updateSalary";
	} else {
		// 新增时 数据处理
		param.__status = 'add';
		url = "/salary/saveSalary";
		param.state = "draft";
	}
	// 提交后台保存数据转换为JSON 格式
	var data = JSON.stringify(param);
	//保存提交后台
	if (url)
		ajaxSubmit(url, data, function(data) {
			if (data['added']) {
				var picking = data['added'];
				picking_id = picking['id'];
			}
			if (parseInt(data['status']) > 0) {
				$.ligerDialog.success('保存成功', '操作完成', reloadPage);
			} else {
				$.ligerDialog.error('保存失败');
			}

		});

}

//界面的返回处理，实际是关闭标签处理。
function toBack() {
	//关闭修改界面
	parent.tabManager.removeTabItem("modify_salary");
	//关闭明细界面
	parent.tabManager.removeTabItem("mx_salary");
	//关闭新增界面
	parent.tabManager.removeTabItem("new_salary");
}
//清空表单
function resetArea() {
	toReset('#a_center input:not(.readonly),select,textarea');
}







var manager, g;
function f_initGrid(){ 
   g =  manager = $("#pop_div #form_table").ligerGrid({
        columns: [
            { display: '员工编号', name: 'userid',width: '10%'},
            { display: '身份证号', name: 'ssn',width: '30%'},
            { display: '性别', name: 'sex',width: '10%'},
            { display: '姓名', name: 'name',width: '10%'},
            { display: '手机', name: 'mobile_phone',width: '20%'},
            { display: '住址', name: 'address',width: '20%'},
            { display: '固话', name: 'fix_phone',width: '20%'},
            { display: '所属公司', name: 'company_id',width: '20%'},
            { display: '所属部门', name: 'dept_id',width: '20%'},
        ],
        onSelectRow: function (rowdata, rowindex)
        {
            $("#txtrowindex").val(rowindex);
        },
        enabledEdit: true,clickToEdit: true, isScroll: false,  
        data:EmployeeData,
        checkbox: true, //是否显示复选框
        pageSize: 20, //每页行数
        alternatingRow: true, //是否附加奇偶行效果行
        usePager:true,
        editorTopDiff:2,
        editorLeftDiff:2
    });   
}
//弹窗
$(function(){
	$('#pop_add_button').bind('click',function(){
		var data = manager.getSelectedRow();
		var pop_add_form = $('#form_content');
	    pop_add_form.find('input:not(:button)').each(function(i){
	    	$(this).val(data[""+$(this).attr('name')+""]);
	    });
	});
});
function help_pop(){
	$('#addMx_Modal').on('shown.bs.modal', function () {
	  f_initGrid();
	});
	$('#addMx_Modal').modal('show');
}
function display_help(){
	$("#help").css("display","inline");
}
function help_hidden(){
	
}